package com.newy.web.sys;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.newy.core.BaseController;
import com.newy.core.util.Converter;
import com.newy.core.util.LangUtils;
import com.newy.domain.sys.Department;
import com.newy.service.sys.DepartService;

/**
 * 机构管理控制类，包括单位管理和部门管理
 * @author LinZongxue
 *
 */
@Controller
@RequestMapping("sys/depart")
public class DepartController extends  BaseController{
	@Resource private DepartService departSvc;

	@RequestMapping("getDepartTreeGridData") @ResponseBody
	public List<Map<String, Object>> getDepartTreeGridData(String node){
		List<Department> departs = departSvc.getChildrenDeparts(LangUtils.parseLong(node));
		return new Converter().addConstField("checked", false).toListOfMap(departs);
	}
	
	@RequestMapping("getDepartTreeData") @ResponseBody
	public List<Map<String, Object>> getDepartTreeData(String node){
		List<Department> departs = departSvc.getChildrenDeparts(LangUtils.parseLong(node));
		return  new Converter().changeField("text", "name").toListOfMap(departs);
	}
	
	@RequestMapping("saveDepart") @ResponseBody
	public Department saveDepart(Department org){
		departSvc.saveDepart(org);
		return org;
	}
	
	@RequestMapping("getDepart")
	public @ResponseBody Department getDepart(Long id){
		return departSvc.getDepart(id);
	}
	
	@RequestMapping("deleteDeparts")
	public @ResponseBody void deleteDeparts(Long[] ids){
		departSvc.deleteDeparts(ids);
	}
}
